package wqlspringboot.springbootcrud.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wqlspringboot.springbootcrud.cv.JieGuo;
import wqlspringboot.springbootcrud.entity.User;
import wqlspringboot.springbootcrud.service.UserService;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/17 20:58
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户后台管理系统")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    @ApiOperation(value = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", defaultValue = "1", required = true, value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", defaultValue = "3", required = true, value = "条数", dataType = "int")
    })
    public PageInfo<User> list(Integer current,Integer pageSize){
        return userService.findByPage(current, pageSize);
    }
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加")

    public JieGuo add(@RequestBody User user){
        return userService.addUser(user);
    }
    @DeleteMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", defaultValue = "1", required = true, value = "编号", dataType = "int")
    public JieGuo delete(Integer id){
        return userService.deleteById(id);
    }
    @PutMapping("/update")
    @ResponseBody
    @ApiOperation(value = "修改")
    public JieGuo update(@RequestBody User user){
        return userService.update(user);
    }
}
